package com.kadron.dao;

import javax.persistence.NoResultException;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;

import com.kadron.entity.ConfirmKey;

@AutoCreate
@BypassInterceptors
@Name("confirmKeyDAO")
public class KConfirmKeyDAO extends KDAO<ConfirmKey> {

	public ConfirmKey getUserKadrons(String key, long userId) {
		try {
			return (ConfirmKey) getEntityManager().createQuery("SELECT c FROM ConfirmKey c WHERE c.confirmKey = :key AND c.user.id=:user_id AND c.confirmed=false")
			.setParameter("key", key)
			.setParameter("user_id", userId)
			.getSingleResult();			
		} catch (NoResultException e) {
			return null;
		}
	}
}
